package com.example.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.dto.Result;
import com.example.dto.ResultUtil;

/**
 * 在控制层的切面定义全局异常处理
 * @author jiaqi.liu
 *
 */
@ControllerAdvice
public class ExceptionHandle {
	
	/**
	 * 全局异常处理
	 * @param e
	 * @return
	 */
	@ExceptionHandler(value=Exception.class)
	@ResponseBody
	public Result doException(Exception e){
		
		if(e instanceof BusinessException){

			  BusinessException ee=(BusinessException)e;
			  return ResultUtil.error(ee);
		}
				
		return ResultUtil.error(e.getMessage());
	}


}
